/**
 * Filename: SettingActivity.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/9 2:36
 */
package com.github.postsanf.yinian.activity;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.animation.OvershootInterpolator;

import com.github.postsanf.yinian.BaseActivity;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.CardMoreWallAdapter;
import com.github.postsanf.yinian.bean.YNStatus;
import com.github.postsanf.yinian.constants.ISkinUpdate;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.utils.SkinPackageManager;
import com.github.postsanf.yinian.utils.WrapContentGridLayoutManager;
import com.github.postsanf.yinian.view.SpacesItemDecoration;
import com.github.postsanf.yinian.ynlist.HeaderSpanSizeLookup;
import com.github.postsanf.yinian.ynlist.YNRecyclerViewAdapter;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

import jp.wasabeef.recyclerview.animators.ScaleInAnimator;

public class CardAlbumMoreActivity extends BaseActivity implements ISkinUpdate {
    private List<String> tempUris;
    private Toolbar mToolbar;
    private Resources mResource;
    private YNStatus mCurStatus;
    private YNRecyclerViewAdapter mYNRecyclerViewAdapter;
    private WrapContentGridLayoutManager mGridLayoutManager;
    private RecyclerView rv_home_album;
    private CardMoreWallAdapter mAdapter;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yn_act_card_more);
        initDatas();
        initView();
    }

    private void initDatas() {
        mCurStatus = YNSingleton.getInstance().getCurStatus();
        tempUris = mCurStatus.getUrl();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    private void initView() {
        mToolbar = (Toolbar) findViewById(R.id.cardpic_toolbar);
        setSupportActionBar(mToolbar);
        mToolbar.setNavigationIcon(R.drawable.ic_return);
        rv_home_album = (RecyclerView) findViewById(R.id.rv_home_album);
        rv_home_album.setItemAnimator(new ScaleInAnimator(new OvershootInterpolator(1f)));
        rv_home_album.getItemAnimator().setAddDuration(500);
        rv_home_album.getItemAnimator().setRemoveDuration(500);
        rv_home_album.getItemAnimator().setMoveDuration(500);
        rv_home_album.getItemAnimator().setChangeDuration(500);
        mAdapter = new CardMoreWallAdapter(this, tempUris, mCurStatus);
        rv_home_album.setHasFixedSize(true);
        SpacesItemDecoration decoration = new SpacesItemDecoration(3);
        rv_home_album.addItemDecoration(decoration);
        mYNRecyclerViewAdapter = new YNRecyclerViewAdapter(mAdapter);
        rv_home_album.setAdapter(mYNRecyclerViewAdapter);
        mGridLayoutManager = new WrapContentGridLayoutManager(this, 3);
        mGridLayoutManager.setSpanSizeLookup(new HeaderSpanSizeLookup((YNRecyclerViewAdapter) rv_home_album.getAdapter(), mGridLayoutManager.getSpanCount()));
        rv_home_album.setLayoutManager(mGridLayoutManager);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void updateTheme() {
        if (mToolbar != null) {
            try {
                mResource = SkinPackageManager.getInstance(this).mResources;
                mToolbar.setNavigationIcon(mResource.getDrawable(mResource.getIdentifier("ic_return", "drawable", "com.github.postsanf.skinby")));
                mToolbar.setBackgroundColor(mResource.getColor(mResource.getIdentifier("yncolor", "color", "com.github.postsanf.skinby")));
                mToolbar.setTitleTextColor(mResource.getColor(mResource.getIdentifier("border_color", "color", "com.github.postsanf.skinby")));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    // 友盟统计
    public void onResume() {
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
        super.onResume();
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }

}
